/*
 * @(#)UserService.java 2020/7/8 11:43 下午
 *
 * Copyright (c) 2010 by rayootech.com. All rights reserved.
 */
package com.nuctech.formlogin.service;

import com.nuctech.formlogin.dao.UserDao;
import com.nuctech.formlogin.model.User;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 用户服务接口
 *
 * @author lilu
 * @date 2020/7/8 11:43 下午
 * @since 1.0.0
 */
@Service
@AllArgsConstructor
public class UserService implements UserDetailsService {

	private final UserDao userDao;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		User user = this.userDao.findUserByUsername(username);
		if (user == null) {
			throw new UsernameNotFoundException("用户不存在！");
		}
		return user;
	}

}
